var express = require('express');
var router = express.Router();

var db = require('../sqldb/index.js');
var patient =require('../model/patient.js')

router.post('/', function(req, res, next) {
	return db.sequelize.transaction(function(t){
		console.log("+++++++++++++++++++")
		if (req.body.pConsultingRoom=='') {
			return patient(db.sequelize).update({
				pQueue: req.body.pQueue,
				reportTime: req.body.reportTime,
				triageTime: req.body.triageTime
			},{
				where:{
					pCardNum:req.body.pCardNum
				}
			}).then(function(data){
				res.json({
					status:1,
					msg:'',
					result:data
				})
			}).catch(function(err){
				res.json({
					status:0,
					msg:err,
					result:''
				})
				console.log("发生错误：" + err);
			});
		}else{
			return patient(db.sequelize).update({
				pQueue: req.body.pQueue,
				pConsultingRoom: req.body.pConsultingRoom,
				reportTime: req.body.reportTime,
				triageTime: req.body.triageTime
			},{
				where:{
					pCardNum:req.body.pCardNum
				}
			}).then(function(data){
				res.json({
					status:1,
					msg:'',
					result:data
				})
			}).catch(function(err){
				res.json({
					status:0,
					msg:err,
					result:''
				})
				console.log("发生错误：" + err);
			});

		}
		
	})
});

module.exports = router;